﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace SpaceInvade.Ships
{
    class Explode
    {
        Texture2D spriteSheet;
        int deathState = 2;
        int srcImgPosX = 0;
        int srcImgPosY = 0;
        int counter = 1;
        int column = 3;
        int row = 3;
        Rectangle ship;
        Rectangle srcImage;
        float Scale = 1f;
        // Section size of source image
        int imageSize = 64;
        public Explode(ContentManager _Content)
        {
            // Create Explode object and load texture
            spriteSheet = _Content.Load<Texture2D>(@"Textures\Explode");
            srcImgPosX = column * imageSize;
            srcImgPosY = row * imageSize;
        }
        // Check status of explosion
        public int CheckFinished(Rectangle _ship)
        {
            ship = _ship;
            return deathState;
        }
        // Draw explosion
        public void Draw(SpriteBatch spriteBatch, Rectangle DrawnLocation)
        {
            // Loops to draw images for correct duration and cycles.
            if (counter == 5)
            {
                        column--;
                        if (column == 0 && row != 0)
                        {
                            column = 3;
                            row--;
                        }
                counter = 1;
                row = 0;
                srcImgPosX = column * imageSize;
                srcImgPosY = row * imageSize;
            }
            if (column == 0 && row == 0)
            {
                Scale = 1f;
                deathState = 3;
            }
            // Scale += .1f;
            counter++;
            // Draw select image and draw
            srcImage = new Rectangle(srcImgPosX, srcImgPosY, imageSize, imageSize);
            // spriteBatch.Draw(spriteSheet, ship, srcImage, Color.White);
            spriteBatch.Draw(spriteSheet, new Vector2(ship.X, ship.Y), srcImage, Color.White, 0f, 
                new Vector2(DrawnLocation.Width/2, DrawnLocation.Height/2), Scale, SpriteEffects.None, 1);
        }
    }
}
